package thread2;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

public class joinAndget1 {
    public static void main(String[] args) {
        CompletableFuture<String> f1 = CompletableFuture.supplyAsync(() -> {
            try {
                System.out.println("f1 exec");
                TimeUnit.SECONDS.sleep(3);
                return "hello";
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });

        System.out.println(f1.join());;

        System.out.println("end");

        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName());
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return "hello ";
        }).thenApplyAsync((r) -> {
            System.out.println(Thread.currentThread().getName());
            return r + "world";
        });
        System.out.println(future.join());


    }
}
